﻿using Jinjia.Approve.API.Controllers.Base;
using Jinjia.Approve.IService;
using Jinjia.Approve.Model;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using Jinjia.Approve.Model.Input;

namespace Jinjia.Approve.API.Controllers
{
    public class JJFlowCommentController : BaseController
    {
        private readonly IJJFlowCommentService _jJFlowCommentService;
        private readonly ILogger<JJFlowCommentController> _logger;

        public JJFlowCommentController(IJJFlowCommentService jJFlowCommentService, ILogger<JJFlowCommentController> logger)
        {
            _logger = logger;
            _jJFlowCommentService = jJFlowCommentService;
        }

        /// <summary>
        /// 保存评论
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> SaveComment(JJFlowCommentCreateInput input)
        {
            var documentFormValidator = new JJFlowCommentCreateInputValidator();
            var validationResult = await documentFormValidator.ValidateAsync(input);
            //校验入参
            if (validationResult.IsValid)
            {
                var result = await _jJFlowCommentService.SaveComment(input);
                return Success(result);
            }
            return ValidationError(validationResult.Errors);
        }

        /// <summary>
        /// 查询评论
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetComments([FromQuery] JJFlowCommentSearchInput input)
        {
            var validator = new JJFlowCommentSearchInputValidator();
            var validationResult = await validator.ValidateAsync(input);
            //校验入参
            if (validationResult.IsValid)
            {
                var result = await _jJFlowCommentService.GetJJFlowComments(input);
                return Success(result);
            }
            return ValidationError(validationResult.Errors);
        }
    }
}